package com.fast.develop;

import com.fast.develop.management.resource.emuns.ResourceType;
import com.fast.develop.management.resource.vo.ResourceVo;
import com.fast.develop.management.resource.vo.TreeVo;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author 莫寅
 * @createTime 2022-07-31 00:44
 * @desc：
 */
@RestController
@RequestMapping("resource/tree/page")
public class PageDataResourceController {


    @GetMapping
    public ResponseEntity<List<TreeVo<ResourceVo>>> getTree(){
        TreeVo uiFlows = createUiFlows();

        TreeVo defaultUiFlow = createDefaultUiFlow();

        uiFlows.getChildren().add(defaultUiFlow);

        TreeVo systemUiFlow = createSystemUiFlow();

        uiFlows.getChildren().add(systemUiFlow);

        return new ResponseEntity(
                Arrays.asList(
                        uiFlows
                )
                , HttpStatus.OK);
    }

    public TreeVo createUiFlows(){
        TreeVo treeVo = new TreeVo();
        treeVo.setId("ui_flows");
        treeVo.setTitle("UI Flows");
        treeVo.setChildren(new ArrayList<>());
        treeVo.setIconSkin(ResourceType.ui_flows.getIcon());

        ResourceVo resourceVo = new ResourceVo();
        resourceVo.setType(ResourceType.ui_flows);
        treeVo.setData(resourceVo);
        return treeVo;
    }

    public TreeVo createDefaultUiFlow(){
        TreeVo treeVo = new TreeVo();
        treeVo.setId("default_ui_flow");
        treeVo.setTitle("default");
        treeVo.setIconSkin(ResourceType.ui_screen.getIcon());


        ResourceVo resourceVo = new ResourceVo();
        resourceVo.setType(ResourceType.ui_screen);
        treeVo.setData(resourceVo);
        return treeVo;
    }

    public TreeVo createSystemUiFlow(){
        TreeVo treeVo = new TreeVo();
        treeVo.setId("system_ui_flow");
        treeVo.setTitle("system");
        treeVo.setIconSkin(ResourceType.ui_flow.getIcon());


        ResourceVo resourceVo = new ResourceVo();
        resourceVo.setType(ResourceType.ui_flow);
        treeVo.setData(resourceVo);

        treeVo.setChildren(Arrays.asList(
                createPage1SystemUiFlow(),
                createPage2SystemUiFlow(),
                createPage3SystemUiFlow(),
                createPage4SystemUiFlow()
        ));
        return treeVo;
    }

    public TreeVo createPage1SystemUiFlow(){
        TreeVo treeVo = new TreeVo();
        treeVo.setId("page1_system_ui_flow");
        treeVo.setTitle("page1");
        treeVo.setIconSkin(ResourceType.ui_page1.getIcon());

        ResourceVo resourceVo = new ResourceVo();
        resourceVo.setType(ResourceType.ui_page1);
        treeVo.setData(resourceVo);
        return treeVo;
    }

    public TreeVo createPage2SystemUiFlow(){
        TreeVo treeVo = new TreeVo();
        treeVo.setId("page2_system_ui_flow");
        treeVo.setTitle("page2");
        treeVo.setIconSkin(ResourceType.ui_page2.getIcon());


        ResourceVo resourceVo = new ResourceVo();
        resourceVo.setType(ResourceType.ui_page2);
        treeVo.setData(resourceVo);
        return treeVo;
    }

    public TreeVo createPage3SystemUiFlow(){
        TreeVo treeVo = new TreeVo();
        treeVo.setId("page3_system_ui_flow");
        treeVo.setTitle("page3");
        treeVo.setIconSkin(ResourceType.ui_page3.getIcon());


        ResourceVo resourceVo = new ResourceVo();
        resourceVo.setType(ResourceType.ui_page3);
        treeVo.setData(resourceVo);
        return treeVo;
    }

    public TreeVo createPage4SystemUiFlow(){
        TreeVo treeVo = new TreeVo();
        treeVo.setId("page4_system_ui_flow");
        treeVo.setTitle("page4");
        treeVo.setIconSkin(ResourceType.ui_page4.getIcon());


        ResourceVo resourceVo = new ResourceVo();
        resourceVo.setType(ResourceType.ui_page4);
        treeVo.setData(resourceVo);
        return treeVo;
    }

}
